﻿using QQ群成员获取.Common;
using System;
using System.ComponentModel;
///using System.Collections.Generic;
using System.IO;
using System.Runtime.InteropServices;
//using System.Linq;
//using System.Text;
using System.Threading;
//using System.Threading.Tasks;
using System.Windows;
//using System.Windows.Controls;
//using System.Windows.Data;
//using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
//using System.Windows.Media.Imaging;
//using System.Windows.Shapes;
using System.Windows.Threading;

namespace QQ群成员获取
{
    /// <summary>
    /// 弹窗提示.xaml 的交互逻辑
    /// </summary>
    public partial class ProcessWindow : Window
    {
        //播放动画函数
        Storyboard story;
        private IExecute executor;
        public bool Finished { get; set; }
        public ProcessWindow(Color color, string strMsg,IExecute executor)
        {
            InitializeComponent();
            this.executor = executor;
            icon.Foreground = new SolidColorBrush(color);
            模板一.Visibility = Visibility.Visible;
            labelTip.Text = strMsg;
            //labelTip.Content = strMsg;
            动画播放("打开");
        }
        private void 动画播放(string a)
        {
            story = (Storyboard)FindResource(a);
            BeginStoryboard(story);
        }
        
        private void exit()
        {
            动画播放("关闭");
            this.Close();
        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            if (executor == null)
            {
                Finished = false;
                this.Close();
                return;
            }
            动画播放("旋转");
            using (BackgroundWorker bw = new BackgroundWorker())
            {
                bw.RunWorkerCompleted += Bw_RunWorkerCompleted;//完成后返回
                bw.DoWork += Bw_DoWork;
                bw.RunWorkerAsync();//开始执行
            }
        }

        private void Bw_DoWork(object sender, DoWorkEventArgs e)
        {
            Finished = executor.DoSomeThing();
        }

        private void Bw_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            this.Close();
        }
    }
}
